#define  _CRT_SECURE_NO_WARNINGS
#include <queue>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr.begin(), arr.end());
	priority_queue<int> q;
	for (int i = 0; i < n;)
	{
		int tmp = arr[i];
		int tmp_num = 0;
		while (i < n && arr[i] == tmp)  //
		{
			tmp_num++;
			i++;
		}
		q.push(tmp_num);
	}
	m -= q.size();
	if (m < 0 || m > n)
	{
		cout << -1;
		return 0;
	}
	if (m == 0) 
	{
		cout << q.top();
		return 0;
	}
	while (m--)
	{
		int max_long = q.top(); q.pop();
		if (max_long % 2)
			q.push(max_long / 2 + 1), q.push(max_long / 2 + 1);
		else
			q.push(max_long / 2), q.push(max_long / 2);
	}
	cout << q.top();
}
/*
8 7
2 2 3 3 3 6 0 1
*/